home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++,comp.lang.c
- From: fred@genesis.demon.co.uk (Lawrence Kirby)
- Path: dd.chalmers.se!news.chalmers.se!sunic!pipex!demon!genesis.demon.co.uk!fred
- Subject: Re: Here's a neat idiom for y'all...
- References: <CMu245.DE3@marin.cc.ca.us> <2mb4hs$4vs@crl.crl.com> <lfw.763998847@pssparc2.oc.com> <2mdapj$9ph@crl2.crl.com> <EJH.94Mar21140731@larry.gsfc.nasa.gov> <2ml75l$d00@chico.staf.phil.ruu.nl> <1994Mar22.163726.18125@mksol.dseg.ti.com>
- Organization: none
- Reply-To: fred@genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- Lines: 27
- Date: Tue, 22 Mar 1994 20:16:35 +0000
- Message-ID: <764367395snz@genesis.demon.co.uk>
- Sender: usenet@demon.co.uk
- Xref: dd.chalmers.se comp.lang.c++:14076 comp.lang.c:12260
-
- In article <1994Mar22.163726.18125@mksol.dseg.ti.com>
- mccall@mksol.dseg.ti.com "Fred McCall" writes:
-
- >: ANd besides, any half-decent compiler will emit a warning on construct like
- >: "if (a = b)", so the probelm is non-existent to begin with.
- >
- >I hate compilers that do this. It's one of those messages I turn off
- >(because this isn't a mistake that I, personally, make -- I make other
- >mistakes, instead -- and because there are a lot of times when I *am*
- >doing an assignment in the conditional clause and I don't want my real
- >errors obscured by a bunch of noisy warnings).
-
- It's common to add an extra set of parentheses to indicate that this is what
- was really intended as in:
-
- if ((a = b))
-
- Compilers like gcc recognise this and suppress the warning. It also makes
- things much clearer to somebody else maintaining the code. It's quite natural
- for assignments in expressiojns to be parenthesised e.g.
-
- if ((ch = getchar()) == EOF)
-
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-